package cn.zxh.csdn_maven;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;

import cn.zxh.csdn_maven.atomy.auth.Login;
import cn.zxh.csdn_maven.atomy.auth.GetSourceList.SourceService;
import cn.zxh.csdn_maven.atomy.auth.letter.Letter;
import cn.zxh.csdn_maven.atomy.auth.letter.RelationSource;
import cn.zxh.csdn_maven.base.pojo.User;


/**
 * Hello world!
 *
 */
public class App 
{
	private static Logger logger = Logger.getLogger(App.class);
	public static void main(String[] args) throws Exception {
		User user = new User("870775401@qq.com","QQ15996779085");
		Login login = new Login(user);
		login.start();
		//发送内容
		String content = "你好《https://zxhtom.oschina.io》欢迎访问个人网页";
		/**获取发送人*/
		HttpClient client = new DefaultHttpClient();
		SourceService sourceService = new RelationSource();
		Map<String, Object> resulMap = sourceService.run(client, new HashMap<String, Object>());
		JSONArray jsonArray = (JSONArray) resulMap.get("userSource");
		for (Object object : jsonArray) {
			/**没封发送时间间隔*/
			JSONObject json = (JSONObject) object;
			String username = json.getString("username");
			Letter letter = new Letter();
			boolean flag = letter.start(username, content);
//			boolean flag=true;
			if (flag) {
				logger.info("发送成功");
				rest();
			}
		}
	}
	
	public static void rest(){
		 try{
			 System.out.println("此次执行完成，需要休息一天。");
             Thread.currentThread();
			Thread.sleep(1000*60*60*12);
          }catch(InterruptedException ie){
              ie.printStackTrace();
          }
	}
}
